package com.athuawei.readwrite;

import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 队列： 先进先出（FIFO)
 * 栈： LIFO
 */
public class ReadWriteLockDemo2 {

    public static void main(String[] args) {
        // 可重入读写锁对象
        ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        ReentrantReadWriteLock.ReadLock readLock = readWriteLock.readLock();
        ReentrantReadWriteLock.WriteLock writeLock = readWriteLock.writeLock();

        //锁降级
        // 2.获取读锁
        readLock.lock();
        System.out.println(" ---- read");

        //1.获取到写锁
        writeLock.lock();
        System.out.println("at hua wei");


        // 3.释放写锁
//        writeLock.unlock();

        // 4.释放读锁
//        readLock.unlock();
    }
}
